#ifndef _TRIGGERROAD_H
#define _TRIGGERROAD_H

#include <iostream>
#include <vector>

#include <TObject.h>
#include <TROOT.h>

class TriggerRoad : public TObject
{
public:
  //Flag
  bool isValid(); //{ return detectorIDs.size() == 4 && isEnabled; }

  //Insert a hodo paddle into the road
  void addElement(int detectorID, int elementID);
  
  //Setters
  void enable() { isEnabled = true; }
  void disable() { isEnabled = false; }

  //Getters
  int getNElements() { return detectorIDs.size(); }
  int getDetectorID(int i) { return detectorIDs[i]; } 
  int getElementID(int i) { return elementIDs[i]; }

  //The total weight and ratio of target weight
  double weight() { return targetWeight + dumpWeight; }
  double ratio() { return targetWeight/(targetWeight + dumpWeight); }

  //T/B , L/R
  int getTB();
  int getLR();
  int getRevH1LR();
  int getBigH1LR();
  int getBigH1TB();
  int getTBRevH1LR(int shiftN);
  //Clear the container
  void clear();

  //Overriden operators for comparison and sort
  bool operator==(const TriggerRoad& elem) const;
  bool operator<(const TriggerRoad& elem) const { return targetWeight/(targetWeight + dumpWeight) > elem.targetWeight/(elem.targetWeight + elem.dumpWeight); }

public:
  //Unique road ID
  int roadID;

  //Weights
  double targetWeight;
  double dumpWeight;

private:
  //Flag 
  bool isEnabled;

  //hodo paddles
  std::vector<int> detectorIDs;
  std::vector<int> elementIDs;

  ClassDef(TriggerRoad, 1)
};

class Trigger : public TObject
{
public:
  bool operator==(const Trigger& elem) const;
  bool operator<(const Trigger& elem) const { return targetWeight/(targetWeight + dumpWeight) > elem.targetWeight/(elem.targetWeight + elem.dumpWeight); }

  double weight() { return targetWeight + dumpWeight; }
  double ratio() { return targetWeight/(targetWeight + dumpWeight); }

  int triggerID;
  double targetWeight;
  double dumpWeight;

  TriggerRoad p_road;
  TriggerRoad m_road;

  ClassDef(Trigger, 1)
};

#endif
